Repository navigation
feat: stream background shell output live and convert client MCP servers to the backend's wire shape - #459
Merged
Conversation
…nd agents as subagents - background.ts: a task that carries a childSessionId but no taskKind is a subagent — SubagentSpawned reaches the wire before the task event and was filed as "other" for good; output tails are cumulative snapshots, diffed before they are streamed as terminal_output_chunk; killed, stopped, lost, timed_out and spawn_error settle the task instead of leaving it running - background-tasks.ts: the output tail was forwarded only on the reused launch-card path, which needs _meta.terminal_output (Zed) — every task event now reaches the V2 face, settled per session in event order - tests: 9 new cases in tests/v2-background.test.ts
… output file - background.ts: a running background shell publishes nothing on the wire while it runs (the adapter watches output progress for foreground runs alone) and the end event's tail is the HEAD of the output file — the V2 face now tails the task's output file itself (every 500 ms, a 64 KiB catch-up cut to a line start, chunks of at most 256 KiB never split inside a UTF-8 sequence, read to the end before the exit frame) and skips the end tail once the file delivered anything - background-tasks.ts: V2 notes settle per session in event order (settleV2) so two task events cannot land out of order - tests: tests/v2-background.test.ts
… and authorization gotchas - AGENTS.md: the V2 face targets ZCode 4.0 and later only; why a running background shell's output is not on the wire, how a background agent is told from other tasks by its first event, which client reuses a launch card, the archive HTTP path, the child transcript replay rule, who is offered MCP authorization's URL form, and the v4 query watermark behind the rewind reads
…faces - #457: the backend's session/create takes ONE strict shape (a stdio entry without type or _meta and with env as a required name/value array, an http entry with headers as pairs); forwarded verbatim, T3 Code's V2 entries failed every create, and the SDK 2.12.0 bump also dropped the SDK 1.x spelling from the V1 schema, so V1 session/new answered -32602 where 0.97.0 took it - client-mcp-servers.ts (new): toWireMcpServers accepts both spellings and rejects the rest with the entry's path; v1SessionParams lets the V1 session/new|resume|load routes parse mcpServers themselves - session.ts: convert at the top of newSession / resumeSession / loadSession, before any state is recorded, so a malformed entry leaves no placeholder - v2/initialize.ts: advertise session.mcp.stdio and session.mcp.http - tests: tests/client-mcp-servers.test.ts; AGENTS.md, docs/REMOTE-CLIENTS.md
- #456: a desktop 4.0 CN sign-in is the zai_cn provider and stores no oauth:bigmodel:access_token — the BigModel plan it is linked to rides oauth:linked_bigmodel ({userId, customerId, accessToken}), honored only while userId is the active profile's id and preferred over a direct sign-in's own token, as upstream's materialFromSnapshot does - project-token.ts: codingPlanLoginToken is the one reader of a family's plan login JWT; official-mcp-auth.ts and settings/coding-plan.ts read through it - tests: project-token.test.ts, account-provider.test.ts; AGENTS.md
Conflict in src/index.ts (buildV1App): #455 added a hand-copied mcpServers schema for the V1 session/fork route where this branch parses mcpServers on the V1 session routes itself (v1SessionParams, #457). The fork route now uses the same parser. The shared fork() still stored the entries raw at this commit; the next commit converts them.
…orking - #455 follow-up: the shared fork() remembered a client's mcpServers verbatim, so a fork's next reload sent entries the backend's strict zcodeProtocolMcpServerSchema rejects — the #457 failure mode on the fork path; the V1 route's own copy of the SDK schema is gone with it - extensions.ts: fork() converts first (toWireMcpServers), so a malformed entry neither forks in the backend nor leaves anything recorded - index.ts: the V1 session/fork route parses mcpServers exactly as session/new does (v1SessionParams) - session.ts: adoptForkedSessionScope takes the converted list - tests: fork-response.test.ts, v2-ops.test.ts; AGENTS.md, docs/PROTOCOL.md
- fork() passed the whole fork result to cacheModelAvailability, but a fork result carries no top-level settings — they sit under `snapshot` (zcodeSessionForkResultSchema) — so the fork's model availability was never cached at fork time and an object-form session/setModel on a fresh fork resolved its level from the personal rule alone until the next resume flight - tests: fork-response.test.ts
…d match - a message's id is shared by the other rows of its turn: 4.0 opens a turn with a turnHeader row under the user message's id, and a reply's reasoning row carries the reply's id, so resolveEditRow and resolveRetryRow took the header (or the reasoning row) and every session/edit_user_message on 4.0 answered "only the latest user message can be edited" — the same for retry_turn by message id - rewind.ts: rowsOfMessage narrows a handle to its message's rows and the target is the userInput / assistantText row among them; an unknown id still answers not found, a wrong-kind or non-editable one the guard message - tests: a 4.0-shaped row window in tests/rewind.test.ts (read live from a one-turn session)
Dopetaiga
added a commit
to Dopetaiga/zcode-acp
that referenced
this pull request
Dec 1, 2026
…on, terminal-by-default statuses, gated stderr dump Review: william0wang#453 (review) - Rebased onto main (0.98.0 + william0wang#455 + william0wang#459); format-only reflows dropped; docs/handoff removed (repo docs are English-only). - F1: one notification turn may serve SEVERAL finished tasks (upstream merges at the drain point) — the queue is snapshotted whole at turn.started, sealed onto the FIRST target only, the rest dropped; backend-side cancelled/killed/stopped never enter the queue (no result turn follows); synthetic <marker> notifications (stall reminders) never seal; markOutstanding/markCancelled purge queued + snapshotted targets. - F2: _zcode/pendingBackgroundWork registered in the V2 private table (src/v2/tools.ts privateMethods) and advertised in v2AgentCapabilities _meta.zcode — reachable and declared on BOTH faces. - F3: liveness is v2TaskOutcome (shared rule, no fourth copy): tracked rawStatus feeds the outstanding filters; toAcpStatus is terminal-by- default (timed_out/spawn_error/lost/stopped/killed settle the card as failed instead of spinning). - F4: the stderr dump fires on SELF-exits only (teardown dumps raced process.exit and were shutdown noise); lines split on bare CR and truncated per line (512 chars); credential-shaped assignments are redacted; the hub skips re-emitting bridge stderr-dump lines (already diary'd by the bridge — were doubled). - F5: the seal is skipped while a V2 connection holds the session (results arrive through the ordered V2 settle chain, not a late out-of-chain tool_call_update). - F6: clamping is surrogate-safe (a cut landing inside a UTF-16 pair moves off the high surrogate — serde_json rejects lone surrogates). - F7: bash resultText rides the bg_* card path too (outputTail ?? stdoutTail), not just the Zed launch-card path. - Also: the seal emission carries .catch (file style); the meta description echo is clamped (1000 chars) — a multi-KB subagent prompt no longer rides every status update. - Tests: merged-turn seal/drift, cancelled-not-queued, failed result turn drops targets, stall-marker skip, V2-holder skip, five upstream terminal statuses (card + query), no-status-yet outstanding, surrogate clamp, meta description clamp, bg_* bash resultText, teardown-no-dump, CR split, per-line truncation, redaction, V2 face probe + declaration.
william0wang
added a commit
that referenced
this pull request
Dec 1, 2026
…s for it (#461) On 4.0 the first event for a subagent is its spawn (SubagentSpawned, a generic session.updated carrying childSessionId and no taskKind); the kind only rides the task event that follows. The listener froze the kind at first sight, so every real subagent task stayed kindless for good and the held-prompt chain read "nothing outstanding": session/prompt returned while the agent was still running (live: prompt at t+9.3s, the card completed at t+15s). The V2 face already classified this way (kindOf, #459); the V1 listener now does the same, and a later sighting that names the kind re-classifies the same tracked task.
Dopetaiga
pushed a commit
to Dopetaiga/zcode-acp
that referenced
this pull request
Dec 1, 2026
…s for it On 4.0 the first event for a subagent is its spawn (SubagentSpawned, a generic session.updated carrying childSessionId and no taskKind); the kind only rides the task event that follows. The listener froze the kind at first sight, so every real subagent task stayed kindless for good and the held-prompt chain read "nothing outstanding": session/prompt returned while the agent was still running (live: prompt at t+9.3s, the card completed at t+15s). The V2 face already classified this way (kindOf, william0wang#459); the V1 listener now does the same, and a later sighting that names the kind re-classifies the same tracked task.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Three reported problems on the ACP faces, plus the V2 background work this branch already carried and one fault found while verifying them:
mcpServersare converted to the backend's wire shape on both faces. The backend'ssession/create/session/resumetake ONE strict shape (stdio{name, command, args, env: [{name, value}]}with notype/_meta; http/sse{name, type, url, headers: [...]}); forwarded verbatim, T3 Code's V2{type: "stdio", …}failed every session create withUnrecognized key: "type". The SDK 2.12.0 bump had also dropped the SDK 1.x spelling (env/headersas string maps) from the V1 schema, so 0.98.0's V1session/newanswered -32602 where 0.97.0's took it. Newsrc/config/client-mcp-servers.ts:toWireMcpServersaccepts both spellings, the V1session/new|resume|load|forkroutes parsemcpServersthemselves (v1SessionParams), and every face converts before any state is recorded — the sharedfork()included (fix: answer V1 session/fork in the ACP draft's shape and populate fork scope #455 follow-up: a fork's next reload sent what it remembered verbatim, and the fork result's model list is now cached fromsnapshot.settings, where it actually lives).zai_cnprovider and stores nooauth:bigmodel:access_token; the BigModel plan it is linked to ridesoauth:linked_bigmodel({userId, customerId, accessToken}), honored only whileuserIdis the active profile's id and preferred over a direct sign-in's own token — as upstream'smaterialFromSnapshotdoes.codingPlanLoginToken(config/project-token.ts) is now the one reader of a family's plan login JWT (entitlement, the project-token exchange, official MCP auth, the reset cards).taskKind, else by thechildSessionIdof their first event (SubagentSpawned); every upstream terminal status ends the V2 item.entityIdof the message they belong to — 4.0 leads a turn with aturnHeaderrow under the user message's id, and a reply'sreasoningrow carries the reply's id — so the first id match was a row withoutactions, and every V1session/edit_user_message/session/retry_turnaddressed by message id failed with the backend'sguard.actionUnavailable. The target is now the row of the asked kind among the message's own rows (src/handlers/rewind.ts).Closes #457
Closes #456
Verification
vitest run: 155 files / 1737 tests;tsc --noEmitclean;eslint .at 0 errors. Every new group was reverse-checked (the cases fail with the fix removed)..zcode/scratch/v2-probes/live/mcp-shapes.live.ts).dist/(real backend, real HOME), model pinned to GLM-5.3-Flash. V2: 30 steps green (prompt, queue while running + cancel + sendNow, file-changing turn, change detail, file rewind, resume, fork, archive / list / unarchive, background shell + cancel, close); the 31st,_zcode/queue/setAutoDrain, answers the pre-command view by design and its push carries the assertion. V1: 12/12 steps (new, prompt, tail load,load_earlier,session/edit_user_message, metadata attach, idle cancel) — the edit step rewinds the latest user message, the backend runs the replacement turn and the reply renders; on 0.98.0 the same step failed withguard.actionUnavailable.gpui-liveprobe, productionAcpConnection+SessionCore): handshake, new, pin, one GLM-5.3-Flash turn; the background shell's output arrived as oneterminal_output_chunkper second while it ran, exit frame last,session/closeretired it.Notes
session/forkin its setup methods for the fork path to work end to end — fix: register a session/fork answer as a session so the fork's first prompt is routed zcode-acp-martty#8.